<?php

namespace App\Http\Controllers\H5;

use App\Http\Controllers\Controller;
use App\Models\Attachment;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class AttachmentController extends Controller
{
    public function store(Request $request)
    {
        $requestFile = $request->file('attachment');
        $file = Storage::put('h5/' . Carbon::now()->format('Y-m-d'), $requestFile);
        $url = Storage::url($file);

        return $this->response->created(null, Attachment::create([
            'url' => $url,
            'file' => $file,
            'mime_type' => $requestFile->getMimeType()
        ]));
    }
}
